'use strict';
	angular.module('customer.fileCustomerSingle', [])

	.controller('fileCustomerSingleCtrl'
			,['$rootScope', '$scope', 'apiService','systemService'
			  ,'BizData', '$uibModal', '$ocLazyLoad'
			   , f])//控制器结束
	function f($rootScope,$scope, apiService,systemService
					   , BizData, $uibModal, $ocLazyLoad
					   ) {
		var Model = this;
		

		
//		$scope.path = $rootScope.path;
//		$scope.createPermission = $rootScope.path + ':create';
		
		//定义页面级别的变量

		var billType = 'KHDA';
		var billTypeName = "客户档案";
		var systemCode = $rootScope.winid; //系统代码

		/////////////////////////////////////////////////////////////////////////////////////////////////

		
		var userId;
		var enterpriseNo;
		var enterpriseName;
		
		
		/**
		name:bizData#onNewCreateParam
		description: <b>[回调型事件]</b>业务新增数据创建新增参数事件，可以增加和修改用户自定义的参数
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"param" : {justep.Request.ActionParam} 新增参数对象,
			"defaultValues" : array - 新增行的默认值数组 ，数组的长度决定新增行数，数组中的对象是列的默认值
				defaultValues格式：
					[
						{列名:默认值,...},
						{列名:默认值,...},
						...
					]
		}
		</xmp>	
		@see justep.XData#newData
		@see justep.Request.ActionParam
		*/
		Model.dataMasterNewCreateParam = function(event) {
			event.param = {"billType": billType};
		};

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataMasterBeforeNew = function(event) {
			
		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataMasterAfterNew = function(event){
			event.source.setValue('storageTypeD','cus',event.id);
			event.source.setValue('storageTypeDLabel','客户',event.id);
			
			event.source.setValue('billType',billType,event.id);
			event.source.setValue('billTypeName',billTypeName,event.id);
			event.source.setValue('systemCode',systemCode,event.id);

		};

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataMasterBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		};
		
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataMasterAfterDelete = function(event) {
//			alert('删除之后！')
		};

		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataMasterIndexChanged = function(event) {
			if(event.rowID!=null){
				Model.dataDetail.fMasterID = event.rowID;
	       		Model.dataDetail.refreshData();
			}else{
				Model.dataDetail.clearData();
			}
		};
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataMasterDataChanged = function(event) {
			
		};
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataMasterValueChanged = function(event) {
			
		};
		
		
		Model.dataMasterBeforeSave = function(event) {
			console.log('dataMasterBeforeSave-->',event);
			var isMember = event.source.getValue('isMember',event.source.getCurrentID());
			if(isMember==1){
				//是会员
				var memberNo = event.source.getValue('memberNo',event.source.getCurrentID());
				if(memberNo==null || memberNo==undefined || memberNo==''){
					event.cancel = true;
					alert('会员卡号不能为空！');
				}
			}
		};
		
		
		Model.dataMasterAfterSave = function(event) {
//			console.log('dataMasterAfterSave.event-->',event);
			//这是为了后台生成的客户编码能够刷新到前台来！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
			Model.dataMaster.refreshPageData();			
		};
		
		

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataDetailBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
//			event.cancel = true;
		};
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataDetailAfterDelete = function(event) {
//			alert('删除之后！')
		};
		
		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataDetailIndexChanged = function(event) {

		};
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataDetailDataChanged = function(event) {
			
		};
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataDetailValueChanged = function(event) {
			if(event.column=='iDefault'){
				var currentID = event.source.getID(event.rowIndex);
				if(event.value==1){
					for(var i=0;i<event.source.getCount();i++){
						var rowID = event.source.getID(i);
						if(rowID!=currentID){
							var iDefault = event.source.getValue('iDefault',rowID);
							if(iDefault==1){
								event.source.setValue('iDefault',0,rowID);
							}
						}
					}
				}
			}
		};
		

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataDetailBeforeNew = function(event) {
			// 明细数据新增之前
			// 检查主表中的数据是否完整
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			
			userId = dataMaster.getValue('userId', rowID);
			enterpriseNo = dataMaster.getValue('enterpriseNo', rowID);
			enterpriseName = dataMaster.getValue('enterpriseName', rowID);

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataDetailAfterNew = function(event){
			var dataDetail = event.source;
			var rowID = event.id;

			dataDetail.setValue('userId', userId, rowID);
			dataDetail.setValue('enterpriseNo', enterpriseNo, rowID);
			dataDetail.setValue('enterpriseName', enterpriseName, rowID);

			dataDetail.setValue('fMasterID',dataDetail.fMasterID,rowID);

		};
		
		///////////////////按钮组开始///////////////////////////////////////////////////
		//新建
		Model.add = function(){
			
		     var options = {
			         index : 0,
			         defaultValues : [
			             {
			            	 state:'active'
			            	 ,status:'open'
//			            	 ,audit:'active'
			            	 ,taxType:1
			            	 ,taxTypeLabel:'1.应税内含'
			            	 ,taxRate:0
			            	 ,depositRate:1
			            	 
			            	 ,memberAmount:0
			            	 ,allocatedAmount:0
			            	 ,pendingAmount:0
			            	 ,memberPoints:0
			            	 
			            	 ,billType: billType
			            	 ,orderDate: ':getCurrentDate()'
				             ,employeeNo: ':getCurrentPsmFID()'
					         ,employeeName: ':getCurrentPsmFName()'
				             ,cUsercode: ':getCurrentPersonCode()'
					         ,cUsername: ':getCurrentPersonName()'
						     ,cDatetime: ':getCurrentDateTime()'
							 ,userId: ':getCurrentPersonID()'
							 ,enterpriseNo: ':getCurrentOgnFID()'
							 ,enterpriseName: ':getCurrentOgnLongName()'
							 ,version: 0

			            }//,
//			             {itemNo:'a2',itemDescribe:'b2'}
			         ]
			     };    

			Model.dataMaster.newData(options);

			if($scope.tabpanel!='single'){
				$scope.tabpanel='single'
			}
		};
		
		//修改
		Model.edit = function(){
			/*
			/////////////////////////////////////////////////////////////
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			var userId = dataMaster.getValue('userId',rowID);
			if(userId!=$rootScope.getCurrentPersonID()){
				systemService.dialogMsg('当前数据不是由您创建，您无权进行此操作！');
				return;
			}
			////////////////////////////////////////////////////////////////
			*/
			Model.dataMaster.editData();
			if($scope.tabpanel!='single'){
				$scope.tabpanel='single'
			}
		};
		
		//保存
		Model.save = function() {
			Model.dataMaster.saveData();
		};

		//取消保存
		Model.saveCancel = function() {
			Model.dataMaster.editCancel();
		};
		
		/*
		//不提示直接提交后台删除当前行
		var data = justp.xbl('mainData');
		var deleteConfirm = data.deleteConfirm;
		var directDeleteMode = data.directDeleteMode;
		try{
		    data.deleteConfirm = false;
		    data.directDeleteMode = true;
		    data.deleteData(data.getID());
		}finally{
		    data.deleteConfirm = deleteConfirm;
		    data.directDeleteMode = directDeleteMode;
		}
		*/
		//删除
		Model.remove = function() {
			/*
			/////////////////////////////////////////////////////////////
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			var userId = dataMaster.getValue('userId',rowID);
			if(userId!=$rootScope.getCurrentPersonID()){
				systemService.dialogMsg('当前数据不是由您创建，您无权进行此操作！');
				return;
			}
			////////////////////////////////////////////////////////////////
			*/
			Model.dataMaster.deleteData(Model.dataMaster.getCurrentID());
			Model.dataMaster.refreshData();
		};
		
		//刷新
		Model.refresh = function() {
			Model.dataMaster.refreshData();
		};
		///////////////////按钮组结束///////////////////////////////////////////////////
		///////////////////子表按钮组开始///////////////////////////////////////////////////
		//增加
		Model.addrow = function(){
		     var options = {
			         index : Model.dataDetail.getCount(),
			         defaultValues : [
			             {
			            	 state:'active'
			            	 ,status:'open'
//			            	 ,orderDate:systemService.getCurrentDate(false)
			            	 
			            	 ,systemCode:systemCode
			            	 ,billType:billType
			            	 ,billTypeName:billTypeName
			            	 
			            	 ,iDefault:0
			            	 ,lat:0
			            	 ,lng:0
			            }//,
//			             {itemNo:'a2',itemDescribe:'b2'}
			         ]
			     };    

			Model.dataDetail.newData(options);
		};
		
		Model.delrow = function() {
			 if(Model.dataDetail.directDeleteMode){
				//直接删除
				 if(Model.dataDetail.deleteData(Model.dataDetail.getCurrentID())==0){
//					 Model.dataDetail.refreshData();
				 }
			 }else{
				//前台移除
				 if(Model.dataDetail.removeData(Model.dataDetail.getCurrentID())==0){
//					 Model.dataDetail.recordState = 'delete';
				 }
			 }
		};
		///////////////////子表按钮组结束///////////////////////////////////////////////////

		
		//打开对话框（选择地址）
		Model.triggerRegionCodeClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		var sAddress = dataMaster.getValue('sAddress', rowID);
     		if(sAddress!=null && sAddress!=''){
         		dataMaster.setValue('sAddress', null, rowID);
         		//dataMaster.setValue('sRegion', null, rowID);
         		dataMaster.setValue('sProvince', null, rowID);
         		dataMaster.setValue('sCity', null, rowID);
         		dataMaster.setValue('sZone', null, rowID);
     			return;
     		}
			
			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

			var modalInstance = apiService.openRegionCodeDialog(options);
	        
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
	             		//alert(returnData[i].rowid+'-->'+returnData[i].billTypeName);

	             		dataMaster.setValue('sAddress', returnData[i].regionFullName, rowID);
	             		//dataMaster.setValue('fRegion', returnData[i].fRegion, rowID);
	             		dataMaster.setValue('sProvince', returnData[i].fProvince, rowID);
	             		dataMaster.setValue('sCity', returnData[i].fCity, rowID);
	             		dataMaster.setValue('sZone', returnData[i].fZone, rowID);
	         			
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};

		
		//打开对话框（选择地址）
		Model.grid_fAddressButtonClick = function(){
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
			
			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

			var modalInstance = apiService.openRegionCodeDialog(options);
	        
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	     			
	          		var dataDetail = Model.dataDetail;
	          		var rowID = dataDetail.getCurrentID();
	          		
	             	for ( var i = 0; i < returnData.length; i++) {
	             		//alert(returnData[i].rowid+'-->'+returnData[i].billTypeName);

	             		dataDetail.setValue('fAddress', returnData[i].regionFullName, rowID);
	             		//dataDetail.setValue('fRegion', returnData[i].fRegion, rowID);
	             		dataDetail.setValue('fProvince', returnData[i].fProvince, rowID);
	             		dataDetail.setValue('fCity', returnData[i].fCity, rowID);
	             		dataDetail.setValue('fZone', returnData[i].fZone, rowID);
	         			
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};
		

		//打开对话框（选择经办人）
		Model.triggerOrgNoClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		var employeeNo = dataMaster.getValue('employeeNo', rowID);
     		if(employeeNo!=null && employeeNo!=''){
         		dataMaster.setValue('employeeNo', null, rowID);
         		dataMaster.setValue('employeeName', null, rowID);
     			return;
     		}
			
			
			var options = {};
			options.id = dataMaster.getValue('enterpriseNo',rowID);
			//是否显示人员
			options.psm = true;

			var modalInstance = apiService.openOrgNoDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
//	             		alert(returnData[i].sID+'-->'+returnData[i].sFName);
	             		dataMaster.setValue('employeeNo', returnData[i].sFID, rowID);
	             		dataMaster.setValue('employeeName', returnData[i].sFName, rowID);
	         			
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};

		//解绑用户
		Model.unbingingOgnClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		dataMaster.setValue('ognID', null, rowID);
			
		};
		
		//绑定用户
		Model.bingingOgnClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
			
			var options = {};
			options.recordState = 'none';
			
			var modalInstance = apiService.openOgnNoDialog();
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//console.log('Model.bingingOgnClick.returnData-->>',returnData);
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
//	             		alert(returnData[i].sID+'-->'+returnData[i].sName);
	             		var ognID = returnData[i].sID;
	             		dataMaster.setValue('ognID', ognID, rowID);
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};
		
		
		
		//双击事件
		Model.gridListRowDblclick = function(rowIndex,rowID){
			$scope.tabpanel = 'single';
		}
		
		//打开对话框（选择会员等级）
		Model.triggerMemberLevelClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
//     		var factoryID = dataMaster.getValue('factoryID', rowID);
//     		if(factoryID!=null && factoryID!=''){
//         		dataMaster.setValue('factoryID', null, rowID);
//         		dataMaster.setValue('factoryNo', null, rowID);
//         		dataMaster.setValue('factoryName', null, rowID);
//     			return;
//     		}
			
			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

//			var modalInstance = systemService.openFactoryNoDialog(options);
	        var modalInstance = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/customer/memberLevel/selectSingle',  
	            controller: 'memberLevelSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/customer/memberLevel/selectSingle')
		        }
	        }); 
	        
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
	             		//alert(returnData[i].rowid+'-->'+returnData[i].billTypeName);

	             		dataMaster.setValue('memberLevel', returnData[i].fID, rowID);
	             		dataMaster.setValue('memberLevelLabel', returnData[i].levelLabel, rowID);
	             		dataMaster.setValue('depositRate', returnData[i].depositRate, rowID);//定金比率
	         			
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};
		

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		Model.objects = {"dataMaster" : Model.dataMaster,"dataDetail" : Model.dataDetail};
		
		var options = {};
		options.container = Model;
		options.concept = 'FileCustomer';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/customer/customerInfo/single/create';
		options.reader = '/customer/customerInfo/single/query';
		options.writer = '/customer/customerInfo/single/save';
		options.deleter = '/customer/customerInfo/single/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
		options.master = {"data":"","relation":""};
		options.directDeleteMode = true;
		options.limit = 15;
		options.orderBy = 'customerNo DESC';

		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataMasterIndexChanged;
		options.onBeforeNew = Model.dataMasterBeforeNew;
		options.onAfterNew = Model.dataMasterAfterNew;
		options.onBeforeDelete = Model.dataMasterBeforeDelete;
		options.onAfterDelete = Model.dataMasterAfterDelete;
		options.onValueChanged = Model.dataMasterValueChanged;
		options.onDataChanged = Model.dataMasterDataChanged;
		options.onBeforeSave = Model.dataMasterBeforeSave;
		options.onAfterSave = Model.dataMasterAfterSave;
		options.onNewCreateParam = Model.dataMasterNewCreateParam;
		
		Model.dataMaster = new BizData(options);
//		Model.objects.dataMaster = Model.dataMaster;
		//监视对象中的所有变动
		Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值

		
		var options = {};
		options.container = Model;
		options.concept = 'FileCustomerAddress';
		options.name = 'dataDetail';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/customer/customerInfo/single/createDetail';
		options.reader = '/customer/customerInfo/single/queryDetail';
		options.writer = '';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
		options.master = {"data":"dataMaster","relation":"fMasterID"};
		options.directDeleteMode = false;
		options.orderBy = '';
		

		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataDetailIndexChanged;
		options.onBeforeNew = Model.dataDetailBeforeNew;
		options.onAfterNew = Model.dataDetailAfterNew;
		options.onBeforeDelete = Model.dataDetailBeforeDelete;
		options.onAfterDelete = Model.dataDetailAfterDelete;
		options.onValueChanged = Model.dataDetailValueChanged;
		options.onDataChanged = Model.dataDetailDataChanged;
//		options.rowsWatcherFn = Model.rowsWatcherFn;
		
		Model.dataDetail = new BizData(options);
//		Model.objects.dataDetail = Model.dataDetail;
		//监视对象中的所有变动
		Model.dataDetail.deregRows = $scope.$watch('Model.dataDetail.rows',Model.dataDetail.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		
		
		//打开对话框（选择会计科目）
		Model.triggerCaptionNoClick = function(columnNo,columnName){
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			if(dataMaster.getValue(columnNo, rowID)){
	         	dataMaster.setValue(columnNo, null, rowID);
	         	dataMaster.setValue(columnName, null, rowID);
	         	return;
			}

			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

			var modalInstance = systemService.openCaptionNoDialog(options);

	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;

	         	dataMaster.setValue(columnNo, returnData[0].captionNo, rowID);
	         	dataMaster.setValue(columnName, returnData[0].captionName, rowID);

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
		};
		
		

		
		Model.dataMaster.refreshData();
		
		$scope.tabpanel = 'list';
		
	    return Model;
	}	
	
